<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    :destroyOnClose="true"
    :afterClose="() => (isOkApp = true)"
    switchFullscreen
    @cancel="handleCancel"
  >
    <replenish-goods-bill-form
      ref="realForm"
      :isShow.sync="isOkApp"
      @ok="submitCallback"
      :disabled="disableSubmit"
      :isShowRemark="title"
    />
    <template slot="footer">
      <div v-show="disableSubmit && title == '审核'">
        <a-button key="back" @click="handleApp(2)"> 驳回</a-button>
        <a-button key="submit" type="primary" :disabled="!isOkApp" @click="handleApp(1)"> 通过</a-button>
      </div>
      <div v-show="disableSubmit && title == '详情'">
        <a-button key="back" @click="handleCancel"> 关闭</a-button>
      </div>
      <div v-show="!disableSubmit">
        <a-button key="back" @click="handleCancel"> 关闭</a-button>
        <a-button key="submit" type="primary" :disabled="isDisabled" @click="handleOk"> 确定</a-button>
      </div>
    </template>
  </j-modal>
</template>

<script>
import ReplenishGoodsBillForm from './ReplenishGoodsBillForm'

export default {
  name: 'ReplenishGoodsBillModal',
  components: {
    ReplenishGoodsBillForm,
  },
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      record: {},
      isOkApp: true,
      isDisabled: false,
      unitNameObj: {},
    }
  },
  methods: {
    add() {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.add()
      })
    },
    edit(record) {
      this.visible = true
      this.record = record
      this.$nextTick(() => {
        this.$refs.realForm.edit(record)
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      this.$refs.realForm.handleOk1()
    },
    handleApp(type) {
      this.$refs.realForm.handleApp(type, this.record)
    },
    submitCallback() {
      this.$emit('ok')
      this.visible = false
    },
    handleCancel() {
      this.close()
    }
  },
}
</script>

<style scoped>
</style>